package com.neuronrobotics.opengl.scene;

import java.util.Arrays;


import com.neuronrobotics.replicator.gui.stl.GeneralTransform3D.MatrixOrder;

public abstract class ShapeNode extends SceneNode {
	
	protected GLHandles theHandles;
	//TODO users shouldn't be setting this up?
		
	// number of coordinates per vertex in this array
	protected int coordsPerVertex = 3; //Coordinates per vertex and normal
	protected static final int COORDS_PER_COLOR = 4; //Coordinates per color
		
	protected int drawArrayType;
		
	protected float[] modelTransform;
	
	protected int vertexCount; //Amount of vertices
	protected int vertexStride;// bytes per vertex

	protected float color[] = { 1f, 1f, 1f, 1.0f };
	
	protected float lightPosition[] = {1,1,1,0};
		
	
	protected boolean lightsOn = true;

	public boolean setTransform(float[] newTransform, MatrixOrder matOrder) {
		if(modelTransform==null) modelTransform = new float[16];
		if (newTransform.length < 16)
			return false;
		int len = 16;
		for (int i = 0; i < len; i++)
			this.modelTransform[i] = newTransform[i];
		if(matOrder!=MatrixOrder.COLUMN_MAJOR) MatrixOrder.convertOrder(newTransform, 0, newTransform,0);
		return true;
	}
	
	public void setLightsOn(boolean newLightsOn){
		this.lightsOn = newLightsOn;
	}
	
	public boolean getLightsOn(){
		return this.lightsOn;
	}
	
	protected void setLightPosition(float[] lPos){
		lightPosition = Arrays.copyOf(lPos, 3);
	}
	
	public void setColor(float r, float g, float b, float a){
		color[0] = r;
		color[1] = g;
		color[2] = b;
		color[3] = a;
	}
	

	@Override
	protected boolean setParent(GroupNode newParent) {
		if(this.parentNode!=null&&parentNode.hasChild(this)){
			parentNode.removeChild(this);
		}
		this.parentNode = newParent;
		return true;
	}
		
	@Override
	protected abstract void draw(float[] viewMatrix, float[] projMatrix);

	
}
